#include "RingQueue.hpp"

void* P_run(void* args)
{
  RingQueue<int>* rq = (RingQueue<int>*)args;
  cout << "im producer" << endl;
  while(1)
  {
    int data = rand()%100+1;
    rq->Push(data);
    cout << "producer :" << data << endl;
  }
}

void* C_run(void* args)
{
  auto rq = (RingQueue<int>*)args;
  sleep(3);
  cout << "im consumer" << endl;
  while(1)
  {
    sleep(1);
    int data = 0;
    rq->Pop(data);
    cout << "consumer :" << data << endl;
  }
}


int main()
{
  pthread_t p;
  pthread_t c;
  srand((unsigned int)time(nullptr));
  auto* rq = new RingQueue<int>;
  pthread_create(&p , nullptr , P_run , rq);
  pthread_create(&c , nullptr , C_run , rq);

  pthread_join(p , nullptr);
  pthread_join(c , nullptr);
  delete rq;
  return 0;
}
